package routes

import (
	"github.com/gin-gonic/gin"
	"os"
	"proxy_resource_test/config"
	"proxy_resource_test/controllers"
	"proxy_resource_test/middleware"
	"proxy_resource_test/services/pool_ip"
)

func Init() *gin.Engine {
	var route = gin.New()
	if config.AppConfig.Env == "dev" {
		// 配置 gin 日志输出到标准输出（控制台）
		gin.SetMode(gin.DebugMode)
		gin.ForceConsoleColor()
		gin.DefaultWriter = os.Stdout
	}

	route.Use(gin.Logger())
	route.Use(gin.Recovery())
	route.Use(middleware.Cors())
	var api = route.Group("/api")
	{
		api.GET("ping", controllers.Ping)
		api.POST("add_task", controllers.AddTask)
		api.POST("start_task", controllers.ControlHandler(pool_ip.CmdStart))
		api.POST("stop_task", controllers.ControlHandler(pool_ip.CmdStop)) // 停止任务，删除
		api.POST("task_status", controllers.StatusTask)
		api.POST("task_static", controllers.GetStatic)
		api.POST("task_test", controllers.TestTask) // 测试接口正确了在做修改
	}
	return route
}
